﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Input;

namespace LP2
{
    class ClimateEvents
    {
        int widthWhole;
        int HeightWhole;
        Texture2D imgWhole;
        Texture2D imgRooster;

        public ClimateEvents()
        {
        }

        public void GravityChange(Physic p,float g)
        {
            p.ChangeGravity(g);
        }

        public void WindChange(Physic p,float newResistAir)
        {
            p.setResistanceAir(newResistAir);
        }

        public void WormWhole(Ally a,Background bg)
        {
            //Aqui se crean los agujeros de forma aleatoria
            Random r = new Random();

            int posx1, posx2, posy1, posy2;

            do
            {
                 posx1 = r.Next(0, 800) + 1;
                 posy1 = r.Next(0, 640) + 1;
            }
            while (!Verify(posx1, widthWhole, posy1, HeightWhole,bg.getObstacles()));

            do
            {
                 posx2 = r.Next(0, 800) + 1;
                 posy2 = r.Next(0, 640) + 1;
            }
            while (!Verify(posx2, widthWhole, posy1, HeightWhole,bg.getObstacles()));


        }

        private Boolean Verify(int x,int size_x,int y,int size_y,List<BoundingBox> lista)
        {
            Vector3 min = new Vector3(x,y,0);
            Vector3 max = new Vector3(x+size_x, y+size_y, 0);

            BoundingBox m = new BoundingBox(min, max);

            foreach (BoundingBox b in lista)
            {
                if (b.Intersects(m)) return false;
            }

            return true;
        }

    }
}
